home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / Devpac 2.12 disk 2.adf / arp / ProDocs / Include / libraries / arpbase.i < prev    next >
Text File  |  1988-10-02  |  29KB  |  854 lines

  1.     IFND LIBRARIES_ARPBASE_I
  2. LIBRARIES_ARPBASE_I    SET    1
  3. ***********************************************************************
  4. *
  5. *    AmigaDOS Replacement Project -- Library Include File (Assembler)
  6. *
  7. ***********************************************************************
  8. *
  9. *    History:
  10. *
  11. *    Version:    arpbase.i,v 34.00 02/27/88
  12. *
  13. *    Created by:    SDB
  14. *    Revised:    SDB (v 5.00 05/31/87)
  15. *            *---- Added meaningful alert numbers, revised macros,
  16. *            *---- updated ArpBase structure to reflect current state.
  17. *            *---- Added cheath's ASSIGN return codes as equates.
  18. *            *---- plus usual grunt work (revisions, lvo's, etc.)
  19. *            SDB (v6.04)
  20. *            cdh V7.0
  21. *            *---- added IntuiBase and GfxBase to ArpBase
  22. *            sdb V7.2
  23. *            *---- rearranged for more efficient lib code (ouch).
  24. *            *---- DosBase IntuiBase and GfxBase have *all* changed!
  25. *            *---- Few more alert #'s now get returned,
  26. *            *---- new GURU macro replaces provincial MYALERT.
  27. *            sdb v12 newstuff, see docs
  28. *            cdh V14    Added dos.library offsets, everybody moves!
  29. *            cdh V15 Added (volatile!) FindFirst etc offsets
  30. *            cdh V19 Added structs and constants for wildcards
  31. *            cdh V31 Final edit for V1.0 ARP 10/7/87
  32. *            sdb V31.00
  33. *                Final edits for release of developers materials.
  34. *                Massive changes to make this file correspond
  35. *                more closely with 'C' File.
  36. *
  37. *            SDB V32.00 Add Stuff for version 32, ASyncRun()
  38. *                Returns and data structures.
  39. *            SDB V32.01 Add ERROR_NO_CLI
  40. *            SDB V32.3 Add ResidentPrg stuff
  41. *            SDB V33.4 Final edits for release.
  42. ***********************************************************************
  43. *
  44. *    Copyright (c) 1987, by Scott Ballantyne
  45. *
  46. *    The arp.library, and related code and files may be freely used
  47. *    by supporters of ARP.  Modules in the arp.library may not be
  48. *    extracted for use in independent code, but you are welcome to
  49. *    provide the arp.library with your work and call on it freely.
  50. *
  51. *    You are equally welcome to add new functions, improve the ones
  52. *    within, or suggest additions.
  53. *
  54. *    BCPL programs are not welcome to call on the arp.library.
  55. *    The welcome mat is out to all others.
  56. ***********************************************************************
  57.  
  58.     IFND EXEC_TYPES_I
  59.     INCLUDE "exec/types.i"
  60.     ENDC !EXEC_TYPES_I
  61.  
  62.     IFND EXEC_LIBRARIES_I
  63.     INCLUDE "exec/libraries.i"
  64.     ENDC !EXEC_LIBRARIES_I
  65.  
  66.     IFND EXEC_LISTS_I
  67.     INCLUDE "exec/lists.i"
  68.     ENDC !EXEC_LISTS_I
  69.  
  70.     IFND EXEC_SEMAPHORES_I
  71.     INCLUDE    "exec/semaphores.i"
  72.     ENDC !EXEC_SEMAPHORES_I
  73.  
  74.     IFND LIBRARIES_DOS_I
  75.     INCLUDE "libraries/dos.i"
  76.     ENDC !LIBRARIES_DOS_I
  77.  
  78.     IFND LIBRARIES_DOS_LIB_I
  79.     INCLUDE "libraries/dos_lib.i"
  80.     ENDC !LIBRARIES_DOS_LIB_I
  81.  
  82.  
  83.     STRUCTURE ArpBase,LIB_SIZE    ; Standard library node
  84.         ULONG    SegList        ; Pointer to loaded libcode (a BPTR).
  85.         UBYTE    Flags        ; Not used, yet!
  86.         UBYTE    ESCChar        ; Character to be used for escaping
  87.         LONG    ArpReserved1    ; ArpLib's use only!!
  88.         CPTR    EnvBase        ; Dummy library for MANX compatibility
  89.         CPTR    DosBase        ; Cached DosBase
  90.         CPTR    GfxBase        ; Cached GfxBase
  91.         CPTR    IntuiBase    ; Cached IntuitionBase
  92.         STRUCT    ResLists,MLH_SIZE ; Resource trackers
  93.         ULONG    ResidentPrgList    ; Resident Programs.
  94.         STRUCT    ResPrgProtection,SS_SIZE    ; protection for above
  95.         LABEL    ArpLib_Sizeof
  96.  
  97. *--------------- Following is here only for compatibility with MANX,
  98. *--------------- don't use in new code!
  99.  
  100.     STRUCTURE EnvLib,LIB_SIZE    ; fake library for MANX
  101.         CPTR    EnvSpace    ; access only when Forbidden!
  102.         ULONG    EnvSize        ; size of environment
  103.         ULONG    EnvArpBase    ; for EXPUNGE
  104.         LABEL    EnvLib_Sizeof
  105.  
  106. *---------- Flags bit definitions
  107. *
  108. * These are used in release 33.4, but not by the library code, instead,
  109. * individual programs which are affected check for these. Not ideal, but
  110. * such is life.
  111. *
  112. *-------------------------------------------------------
  113.  
  114.     BITDEF    ARP,WILD_WORLD,0    ; Mixed BCPL/Normal wildcards.
  115.     BITDEF    ARP,WILD_BCPL,1        ; Pure bcpl.
  116.  
  117. *----------- Rest of library style stuff
  118.  
  119. ArpName    MACRO
  120.     dc.b    'arp.library',0
  121.     ds.w    0
  122.     ENDM
  123.  
  124. *---------- Current arp.library version.
  125.  
  126. ArpVersion EQU    34
  127.  
  128. *-------- Alert Object
  129. * The alert object is what you use if you really must return an alert
  130. * to the user.  You would normally OR this with another alert number from
  131. * the alerts.h file.  Generally, these should be NON deadend alerts.
  132. *
  133. * For example, if you can't open ArpLibrary:
  134. *
  135. *    GURU    AG_OpenLib!AO_ArpLib
  136. *----------------------------------------
  137.  
  138. AO_ArpLib    EQU    $00008036    ; alert object
  139.  
  140. *-------- Specific Alerts you can get from ArpLib. -----------*
  141.  
  142. AN_ArpLib    EQU    $03600000    ; alert number
  143. AN_ArpNoMem    EQU    $03610000    ; Arplibrary out of memory.
  144. AN_ArpInputMem    EQU    $03610002    ; No memory for input buffer.
  145. AN_ArpNoMakeEnv    EQU    $83610003    ; No memory to make EnvLib
  146.  
  147. AN_ArpNoDOS    EQU    $83630001    ; Can't open DOS library
  148. AN_ArpNoGfx    EQU    $83630002    ; Can't open graphics
  149. AN_ArpNoIntuit    EQU    $83630003    ; Can't open intuition
  150. AN_BadPackBlues    EQU    $83640000    ; Bad packet returned to SendPacket()
  151.  
  152. AN_Zombie    EQU    $83600003    ; AsyncRun() Exit code didn't.
  153.  
  154. AN_ArpScattered    EQU    $83600002    ; Scatter loading not allowed for lib.
  155.  
  156. *---------- Tiny ALERT macro, assumes ExecBase is already in A6, also that you
  157. *---------- have nothing important in d7, also that you want to return immediately.
  158.  
  159. GURU    MACRO    * optional alert number
  160.     IFNC    '\1',''
  161.     move.l    #\1,D7
  162.     ENDC
  163.     jmp    _LVOAlert(a6)
  164.     ENDM
  165.  
  166. MYALERT    MACRO * ancient compatibility
  167.     GURU    \1
  168.     ENDM
  169.  
  170. *------------- Library Vector Offsets.
  171.  
  172.  
  173. *
  174. * This macro is used to define the DOS offsets without redefining the symbols-
  175. *    To get the DOS symbols, INCLUDE dos_lib.i
  176. *
  177. LIBSKP    MACRO
  178. COUNT_LIB   SET     COUNT_LIB-LIB_VECTSIZE
  179.     ENDM
  180.  
  181.     LIBINIT
  182.  
  183.     LIBSKP    _LVOOpen
  184.     LIBSKP    _LVOClose
  185.     LIBSKP    _LVORead
  186.     LIBSKP    _LVOWrite
  187.     LIBSKP    _LVOInput
  188.     LIBSKP    _LVOOutput
  189.     LIBSKP    _LVOSeek
  190.     LIBSKP    _LVODeleteFile
  191.     LIBSKP    _LVORename
  192.     LIBSKP    _LVOLock
  193.     LIBSKP    _LVOUnLock
  194.     LIBSKP    _LVODupLock
  195.     LIBSKP    _LVOExamine
  196.     LIBSKP    _LVOExNext
  197.     LIBSKP    _LVOInfo
  198.     LIBSKP    _LVOCreateDir
  199.     LIBSKP    _LVOCurrentDir
  200.     LIBSKP    _LVOIoErr
  201.     LIBSKP    _LVOCreateProc
  202.     LIBSKP    _LVOExit
  203.     LIBSKP    _LVOLoadSeg
  204.     LIBSKP    _LVOUnLoadSeg
  205.     LIBSKP    _LVOGetPacket
  206.     LIBSKP    _LVOQueuePacket
  207.     LIBSKP    _LVODeviceProc
  208.     LIBSKP    _LVOSetComment
  209.     LIBSKP    _LVOSetProtection
  210.     LIBSKP    _LVODateStamp
  211.     LIBSKP    _LVODelay
  212.     LIBSKP    _LVOWaitForChar
  213.     LIBSKP    _LVOParentDir
  214.     LIBSKP    _LVOIsInteractive
  215.     LIBSKP    _LVOExecute
  216. ***
  217.     LIBDEF    _LVOPrintf        ; Print formatted data on current output.
  218.     LIBDEF    _LVOFPrintf        ; Print formatted data on file.
  219.     LIBDEF    _LVOPuts        ; Print string\n on stdout.
  220.     LIBDEF    _LVOReadLine        ; Get a line from stdin.
  221.     LIBDEF    _LVOGADS        ; Get args using template
  222.     LIBDEF    _LVOAtol        ; Convert Ascii to long int.
  223.     LIBDEF    _LVOEscapeString    ; Handle escapes in string.
  224.     LIBDEF    _LVOCheckAbort        ; Check for CNTRL-C
  225.     LIBDEF    _LVOCheckBreak        ; Check for CNTRL c d e or f
  226.     LIBDEF    _LVOGetenv        ; Get value of environment variable
  227.     LIBDEF    _LVOSetenv        ; Set value of environment variable
  228.     LIBDEF    _LVOFileRequest        ; Filename Requester
  229.     LIBDEF    _LVOCloseWindowSafely    ; Closes shared IDCMP window w/o GURU
  230.     LIBDEF    _LVOCreatePort        ; Create a message port
  231.     LIBDEF    _LVODeletePort        ; Delete a message port
  232.     LIBDEF    _LVOSendPacket        ; Send a dos packet
  233.     LIBDEF    _LVOInitStdPacket    ; initialize a standard packet
  234.     LIBDEF    _LVOPathName        ; Return Complete pathname of file/directory.
  235.     LIBDEF    _LVOAssign        ; Assign a logical device name
  236.     LIBDEF    _LVODosAllocMem        ; DOS compatible memory allocator
  237.     LIBDEF    _LVODosFreeMem        ; DOS compatible memory free-er
  238.     LIBDEF    _LVOBtoCStr        ; Copy a BCPL string to C string
  239.     LIBDEF    _LVOCtoBStr        ; Copy a C string to BCPL string
  240.     LIBDEF    _LVOGetDevInfo        ; Get pointer to head of DevInfo
  241.     LIBDEF    _LVOFreeTaskResList    ; Free Tracked resources for this task
  242.     LIBDEF    _LVOArpExit        ; Exit, freeing tracked resources.
  243.     LIBDEF    _LVOArpAlloc        ; Allocate memory with tracking
  244.     LIBDEF    _LVOArpAllocMem        ; Track AllocMem allocation
  245.     LIBDEF    _LVOArpOpen        ; Track open files
  246.     LIBDEF    _LVOArpDupLock        ; Track duped locks
  247.     LIBDEF    _LVOArpLock        ; Track allocated locks
  248.     LIBDEF    _LVORListAlloc        ; Like ArpAlloc for free reslist
  249.     LIBDEF    _LVOFindCLI        ; Get a process given a task number
  250.     LIBDEF    _LVOQSort        ; Quick Sort
  251.  
  252.     LIBDEF    _LVOPatternMatch    ; Match a string with a pattern (wildcards!)
  253.     LIBDEF    _LVOFindFirst        ; Search directory w/wildcards
  254.     LIBDEF    _LVOFindNext        ; Continue search w/wildcards
  255.     LIBDEF    _LVOFreeAnchorChain    ; Free mem from FindFirst/Next
  256.  
  257.     LIBDEF    _LVOCompareLock        ; Compare two disk locks
  258.  
  259.     LIBDEF    _LVOFindTaskResList    ; Find resource list for this task
  260.     LIBDEF    _LVOCreateTaskResList     ; Create a new nested task reslist
  261.     LIBDEF    _LVOFreeResList        ; Free an un-attached reslist
  262.     LIBDEF    _LVOFreeTrackedItem    ; Free a tracked item
  263.     LIBDEF    _LVOGetTracker        ; Get a tracker node
  264.  
  265.     LIBDEF    _LVOGetAccess        ; Lock access to a node
  266.     LIBDEF    _LVOFreeAccess        ; Allow resource to flush if lowmem
  267.  
  268.     LIBDEF    _LVOFreeDAList        ; Free a DosAllocmem list
  269.     LIBDEF    _LVOAddDANode        ; Add a node to a DA list
  270.     LIBDEF    _LVOAddDADevs        ; Add devices to a DA list
  271.  
  272.     LIBDEF    _LVOStrcmp        ; Compare two null-terminated strs
  273.     LIBDEF    _LVOStrncmp        ; Compare up to N chars
  274.     LIBDEF    _LVOToupper        ; Convert to UC
  275.     LIBDEF    _LVOSyncRun        ; Run program as subroutine
  276. * Added V32 of arp.library
  277.     LIBDEF    _LVOASyncRun        ; Run program in background
  278.     LIBDEF    _LVOLoadPrg        ; As for LoadSeg(), but searches Res&Path
  279.     LIBDEF    _LVOPreParse        ; Create tokenized PatternMatch string
  280. * V33
  281.     LIBDEF    _LVOStamptoStr        ; Date stamp to string
  282.     LIBDEF    _LVOStrtoStamp        ; Date string to stamp
  283.  
  284.     LIBDEF    _LVOObtainResidentPrg    ; Get a resident program
  285.     LIBDEF    _LVOAddResidentPrg    ; Add it
  286.     LIBDEF    _LVORemResidentPrg    ; Remove it
  287.     LIBDEF    _LVOUnLoadPrg        ; Check Sum code
  288.     LIBDEF    _LVOLMult        ; long mult
  289.     LIBDEF    _LVOLDiv        ; long division, signed
  290.     LIBDEF    _LVOLMod        ; long %
  291.  
  292.     LIBDEF    _LVOCheckSumPrg        ; Refresh checksum for resident code
  293.     LIBDEF    _LVOTackOn        ; Add A1 onto directory string A0
  294.     LIBDEF    _LVOBaseName        ; Get Filename from complete dir string
  295.     LIBDEF    _LVOReleaseResidentPrg    ; True if code is resident and was released.
  296. ***
  297.  
  298. *---------- Return codes you can get from calling Assign:
  299.  
  300. ASSIGN_OK    EQU    0    ; Everything is cool and groovey
  301. ASSIGN_NODEV    EQU    1    ; "Physical" is not valid for assignment
  302. ASSIGN_FATAL    EQU    2    ; Something really icky happened
  303. ASSIGN_CANCEL    EQU    3    ; Tried to cancel something that won't cancel.
  304.  
  305. *--------- Size of buffer you need for ReadLine
  306.  
  307. MaxInputBuf    EQU    256
  308.  
  309. * Macro to declare things as unions:
  310.  
  311. UNION    MACRO    *name,maxsize
  312. UOFFSET    SET    SOFFSET
  313. \1    EQU    SOFFSET
  314. SOFFSET    SET    SOFFSET+\2
  315.     ENDM
  316. * member of union
  317.  
  318. UMEMB MACRO    * name
  319. \1    EQU    UOFFSET
  320.     ENDM
  321.  
  322. ******************************* File Requester *******************************
  323. ********************** Submit the following to FileRequest() *****************
  324. ******************************************************************************
  325.  
  326.     STRUCTURE FileRequester,0
  327.         CPTR    fr_Hail            ; Hailing text
  328.         CPTR    fr_File            ; *Filename array (FCHARS+1)
  329.         CPTR    fr_Dir            ; *Directory array (DSIZE+1)
  330.         CPTR    fr_Window        ; Window requesting or NULL
  331.         UBYTE    fr_FuncFlags        ; Set bitdef's below
  332.         UBYTE    fr_reserved1        ; Set to NULL
  333.         APTR    fr_Function        ; Func to call for wildcards
  334.         LONG    fr_reserved2        ; RESERVED
  335.         LABEL    fr_SIZEOF
  336.  
  337. *****************************************************************
  338. * The following are the equates for fr_FuncFlags. These bits tell
  339. * FileRequest() what your fr_UserFunc is expecting, and what FileRequest()
  340. * should call it for.
  341. *
  342. * You are called like so
  343. * fr_Function(Mask, Object)
  344. * ULONG    Mask
  345. * CPTR    *Object
  346. *
  347. * The Mask is a copy of the flag value that caused FileRequest() to call
  348. * your function. You can use this to determine what action you need to
  349. * perform, and exactly what Object is, so you know what to do and
  350. * what to return.
  351. *
  352.     BITDEF    FR,DoWildFunc,7    ; Call me with a FIB and a name, ZERO return accepts.
  353.     BITDEF    FR,DoMsgFunc,6    ; You get all IDCMP message not for FileRequest()
  354.     BITDEF    FR,DoColor,5    ; Set this bit for that new and differnt look
  355.     BITDEF    FR,NewIDCMP,4    ; Force a new IDCMP (only if fr_Window != NULL)
  356.     BITDEF    FR,NewWindFunc,3 ; You get to modify the NewWindow struct.
  357.     BITDEF    FR,AddGadFunc,2    ; You get to add gadgets
  358.     BITDEF    FR,GEventFunc,1    ; Function to call if one of your gads is selected
  359.     BITDEF    FR,ListFunc,0    ; not implemented.
  360.  
  361. FCHARS    EQU    32            ; Directory name sizes
  362. DSIZE    EQU    33
  363.  
  364. FR_FIRST_GADGET    EQU    $7680        ; User gadgetID's must be less than this.
  365. ************************************************************************
  366. ************************ PATTERN MATCHING ******************************
  367. ************************************************************************
  368.  
  369. * structure expected by FindFirst, FindNext.
  370. * Allocate this structure and initialize it as follows:
  371. *
  372. * Set ap_BreakBits to the signal bits (CDEF) that you want to take a
  373. * break on, or NULL, if you don't want to convenience the user.
  374. *
  375. * If you want to have the FULL PATH NAME of the files you found,
  376. * allocate a buffer at the END of this structure, and put the size of
  377. * it into ap_Length.  If you don't want the full path name, make sure
  378. * you set ap_Length to zero.  In this case, the name of the file, and stats
  379. * are available in the ap_Info, as per usual.
  380. *
  381. * Then call FindFirst() and then afterwards, FindNext() with this structure.
  382. * You should check the return value each time (see below) and take the
  383. * appropriate action, ultimately calling FreeAnchorChain() when there are
  384. * no more files and you are done.  You can tell when you are done by
  385. * checking for the normal AmigaDOS return code ERROR_NO_MORE_ENTRIES.
  386. *
  387.  
  388.     STRUCTURE AnchorPath,0
  389.         CPTR    ap_Base        ; pointer to first anchor
  390.         CPTR    ap_Last        ; pointer to last anchor
  391.         LONG    ap_BreakBits    ; Bits we want to break on
  392.         LONG    ap_FoundBreak    ; Bits we broke on. Also returns ERROR_BREAK
  393.         ULONG    ap_Length    ; Actual size of ap_Buf, set to 0 if none.
  394.         STRUCT    ap_Info,fib_SIZEOF    ; FileInfoBlock
  395.         LABEL   ap_Buf        ; Buffer for path name, allocated by user
  396.         LABEL   ap_SIZEOF
  397.  
  398. *
  399. * Structure used by the pattern matching functions, no need to obtain, diddle
  400. * or allocate this yourself
  401. *
  402.     STRUCTURE Anchor,0
  403.         CPTR    an_Next        ; next anchor
  404.         CPTR    an_Pred        ; previous
  405.         LONG    an_Lock        ; a FileLock pointer (BPTR)
  406.         CPTR    an_Info        ; pointer to a FileInfoBlock
  407.         LONG    an_Status    ; type of this anchor node
  408.         UNION    an_BSTR,2    ; more memory allocated as needed
  409.             UMEMB an_Text    ; actual instance of a BSTRing 
  410.             UMEMB an_Actual    ; bytes 1 and 2
  411.         LABEL   an_SIZEOF
  412.  
  413. * Constants used by wildcard routines, these are the pre-parsed tokens
  414. * referred to by pattern match.  It is not necessary for you to do
  415. * anything about these, FindFirst() FindNext() handle all these for you.
  416.  
  417. P_ANY        EQU    $80    ; Token for '*' or '#?
  418. P_SINGLE    EQU    $81    ; Token for '?'
  419. P_ORSTART    EQU    $82    ; Token for '('
  420. P_ORNEXT    EQU    $83    ; Token for '|'
  421. P_OREND        EQU    $84    ; Token for ')'
  422. P_TAG        EQU    $85    ; Token for '{'
  423. P_TAGEND    EQU    $86    ; Token for '}'
  424. P_NOTCLASS    EQU    $87    ; Token for '^'
  425. P_CLASS        EQU    $88    ; Token for '[]'
  426. P_REPBEG    EQU    $89    ; Token for '['
  427. P_REPEND    EQU    $8A    ; Token for ']'
  428.  
  429. * Values for an_Status, NOTE: These are the actual bit numbers
  430.  
  431. COMPLEX_BIT    EQU    1    ; Parsing complex pattern
  432. EXAMINE_BIT    EQU    2    ; Searching directory
  433.  
  434. * Returns from FindFirst(), FindNext()
  435. * You can also get dos error returns, such as ERROR_NO_MORE_ENTRIES,
  436. * these are in the dos.h file.
  437. *
  438. ERROR_BUFFER_OVERFLOW    EQU    303    ; User or internal buffer overflow
  439. ERROR_BREAK        EQU    304    ; A break character was received
  440.  
  441.  
  442. * Structure used by AddDANode, AddDADevs, FreeDAList
  443. *
  444. * This structure is used to create lists of names,
  445. * which normally are devices, assigns, volumes, files, or directories.
  446.  
  447.     STRUCTURE DirectoryEntry,0
  448.         CPTR    de_Next            ; Next in list
  449.         BYTE    de_Type            ; DLX_mumble
  450.         BYTE    de_Flags        ; For future expansion, do not use!
  451.         LABEL    de_Name            ; name of thing found
  452.         LABEL    de_SIZEOF
  453.  
  454. * Defines you use to get a list of the devices you want to look at.
  455. * For example, to get a list of all directories and volumes, do
  456. *
  457. *    move.l    #DLF_DIRS!DLF_VOLUMES,d0
  458. *    move.l    myDalist(pc),a0
  459. *    SYSCALL    AddDADevs        ; ArpBase already in A6, of course
  460. *
  461. * After this, you can examine the de_Type field of the elements added
  462. * to your list (if any) to discover specifics about the objects added.
  463. *
  464. * Note that if you want only devices which are also disks, you must
  465. * request DLF_DEVICES!DLF_DISKONLY
  466. *
  467.  
  468.     BITDEF    DL,DEVICES,0    ; Return devices
  469.     BITDEF    DL,DISKONLY,1    ; Modifier for above: Return disk devices only
  470.     BITDEF    DL,VOLUMES,2    ; Return volumes only
  471.     BITDEF    DL,DIRS,3    ; Return assigned devices only
  472.  
  473. * Legal de_Type values, check for these after a call to AddDADevs(), or
  474. * use on your own as the ID values in AddDANode()
  475.  
  476. DLX_FILE    EQU    0    ; AddDADevs() can't determine this
  477. DLX_DIR        EQU    8    ; AddDADevs() can't determine this
  478. DLX_DEVICE    EQU    16    ; It's a resident device
  479.  
  480. DLX_VOLUME    EQU    24    ; Device is a volume
  481. DLX_UNMOUNTED    EQU    32    ; Device is not resident
  482.  
  483. DLX_ASSIGN    EQU    40    ; Device is a logical assignment
  484.  
  485. ************************************************************************
  486. ************************** RESOURCE TRACKING ***************************
  487. ************************************************************************
  488.  
  489. *
  490. * NOTE: This is a DosAllocMem'd list, this is done for you when you
  491. * call CreateTaskResList(), typically, you won't need to access/allocate
  492. * this structure.
  493. *
  494.     STRUCTURE ResList,0
  495.         STRUCT    rl_Node,MLN_SIZE  ; Used by arplib to link reslist's
  496.         CPTR    rl_TaskID       ; Owner of this list
  497.         STRUCT    rl_FirstItem,MLH_SIZE    ; List of TrackedResource's
  498.         CPTR    rl_Link        ; For temp removal from task rlist
  499.         LABEL    RL_SIZEOF
  500.  
  501. * The rl_FirstItem list (above) is a list of TrackedResource (below).
  502. * It is very important that nothing in this list depend on the task
  503. * existing at resource freeing time (i.e., RemTask(0L) type stuff,
  504. * DeletePort() and the rest).
  505. *
  506. * The tracking functions return a struct Tracker *Tracker to you, this
  507. * is a pointer to whatever follows the tr_ID variable.
  508. * The default case is reflected below, and you get it if you call
  509. * GetTracker() ( see DefaultTracker below).
  510. *
  511. * NOTE: The two user variables mentioned in an earlier version don't
  512. * exist, and never did. Sorry about that (SDB).
  513. * However, you can still use ArpAlloc to allocate your own tracking
  514. * nodes and they can be any size or shape you like, as long as the
  515. * base structure is preserved.  They will be freed automagically
  516. * just like the default trackers.
  517.  
  518.     STRUCTURE TrackedResource,0
  519.         STRUCT    tr_Node,MLN_SIZE    ; Double linked pointer
  520.         BYTE    tr_Flags        ; Don't touch
  521.         BYTE    tr_Lock            ; Don't touch, for Get/FreeAcess
  522.         SHORT    tr_ID            ; ID for this item class
  523. * The struct DefaultTrackter portion of the structure
  524. * The stuff below this point can conceivably vary, depending
  525. * on user needs, etc.  This reflects the default.
  526.         UNION    tr_Object,4        ; The thing being tracked
  527.             UMEMB tr_Object_tg_Verify    ; for use during TRAK_GENERIC
  528.             UMEMB tr_Object_tr_Resource ; whatever
  529.         UNION    tr_Extra,4        ; only needed sometimes
  530.             UMEMB tr_Extra_tg_Function    ; function to call for TRAK_GENERIC
  531.             UMEMB tr_Extra_tr_Window2    ; for TRAK_WINDOW
  532.         LABEL    trk_SIZEOF        ; trk_ fixes COLLISION WITH TMPRAS...
  533.  
  534. tr_Object_tg_Value EQU tr_Object_tg_Verify
  535.  
  536. * You get a pointer to a struct of the following type when you call
  537. * GetTracker().  You can change this, and use ArpAlloc() instead of
  538. * GetTracker() to do tracking. Of course, you have to take a wee bit
  539. * more responsibility if you do, as well as if you use TRAK_GENERIC
  540. * stuff.
  541. *
  542. * TRAK_GENERIC folks need to set up a task function to be called when an
  543. * item is freed.  Some care is required to set this up properly.
  544. *
  545. * Some special cases are indicated by the unions below, for TRAK_WINDOW,
  546. * if you have more than one window opened, and don't want the IDCMP closed
  547. * particularly, you need to set a ptr to the other window in dt_Window2.
  548. * See CloseWindowSafely() for more info.  If only one window, set this to NULL.
  549.  
  550.     STRUCTURE DefaultTracker,-2
  551.         SHORT    dt_ID        ; Different from C file, but it's ok.
  552.         UNION    dt_Object,4    ; the object being tracked
  553.             UMEMB dt_Resource    ; Whatever
  554.             UMEMB tg_Verify    ; whatever
  555.         UNION    dt_Extra,4
  556.             UMEMB tg_Function    ; function to call for TRAK_GENERIC
  557.             UMEMB dt_Window2
  558.         LABEL    dt_SIZEOF
  559.  
  560. tg_Value EQU tg_Verify    ; ancient compatibility
  561. * Tracked Item Types
  562. *    The id types below show the types of resources which may
  563. * be tracked in a resource list.
  564. *
  565. TRAK_AAMEM    EQU    0        ; Default generic (ArpAlloc) element
  566. TRAK_LOCK    EQU    1        ; File Lock
  567. TRAK_FILE    EQU    2        ; Opened File
  568. TRAK_WINDOW    EQU    3        ; Window (see discussion)
  569. TRAK_SCREEN    EQU    4        ; Screen
  570. TRAK_LIBRARY    EQU    5        ; Opened library
  571. TRAK_DAMEM    EQU    6        ; Pointer to DosAllocMem block
  572. TRAK_MEMNODE    EQU    7        ; AllocEntry() node.
  573. TRAK_SEGLIST    EQU    8        ; Program Segment List
  574. TRAK_RESLIST    EQU    9        ; ARP (nested) ResList
  575. TRAK_MEM    EQU    10        ; Memory ptr/length
  576. TRAK_GENERIC    EQU    11        ; Generic Element
  577. TRAK_DALIST    EQU    12        ; DAlist ( as used by file request )
  578. TRAK_ANCHOR    EQU    13        ; Anchor chain
  579. TRACK_MAX    EQU    13        ; Anything else is tossed.
  580.  
  581.     BITDEF    TR,UNLINK,7        ; Bit for freeing the node
  582.     BITDEF    TR,RELOC,6        ; This element may be relocated (not used yet
  583.     BITDEF    TR,MOVED,5        ; Item moved
  584.  
  585. *--- Returns from CompareLock()
  586.  
  587. LCK_EQUAL    EQU    0    ; Locks refer to the same object
  588. LCK_VOLUME    EQU    1    ; Locks are on the same volume
  589. LCK_DIFVOL1    EQU    2    ; Locks are on different volumes
  590. LCK_DIFVOL2    EQU    3    ; Locks are on different volumes
  591.  
  592. *----------- Stuff For ASyncRun() and friends
  593. *---------- Message sent back on request by an exiting process.
  594. *---------- You request this by putting the address of your
  595. *---------- message in pcb_LastGasp, and initializing the
  596. *---------- ReplyPort variable of the zombiemsg to the port you wish
  597. *---------- the message posted to.
  598.  
  599.     STRUCTURE ZombieMsg,MN_SIZE
  600.         ULONG    zm_TaskNum        ; task ID
  601.         ULONG    zm_ReturnCode        ; Process's return code 
  602.         ULONG    zm_Result2        ; System return
  603.         STRUCT    zm_ExitTime,ds_SIZEOF    ; Date stamp at time of exit
  604.         ULONG    zm_UserInfo        ; for whatever you like
  605.         LABEL    zm_SIZEOF
  606.         
  607. *------------ Structure required by ASyncRun() -- see docs for more info.
  608. *------------
  609.     STRUCTURE ProcessControlBlock,0
  610.         ULONG    pcb_StackSize    ; Stacksize for new process
  611.         BYTE    pcb_Pri        ; Priority of new process 
  612.         BYTE    pcb_Control    ; Control bits, see BITDEF's below.
  613.         APTR    pcb_TrapCode    ; Optional trapcode vector
  614.         ULONG    pcb_Input    ; Optional default input
  615.         ULONG    pcb_Output    ; Optional default output
  616.         UNION    pcb_Console,4
  617.             UMEMB pcb_Splatfile ; file to use for Open("*")
  618.             UMEMB pcb_ConName    ; CON: filename 
  619.         ULONG    pcb_LoadedCode    ; If not null, use this code
  620.         CPTR    pcb_LastGasp    ; ReplyMsg to be filled in by exit code
  621.         CPTR    pcb_WBProcess    ; Valid only when PRB_NOCLI.
  622.         LABEL    pcb_Sizeof
  623.  
  624. *---- bits to set in pcb_Control
  625.  
  626.     BITDEF    PR,SAVEIO,0        ; don't release/check file handles
  627.     BITDEF    PR,CLOSESPLAT,1        ; close splat, must request explicitly
  628.     BITDEF    PR,NOCLI,2        ; Don't want a CLI
  629.     BITDEF    PR,INTERACTIVE,3    ; Set interactive flag = TRUE. Cli's only.
  630.     BITDEF    PR,CODE,4        ; Actual code address. Be Careful!
  631.     BITDEF    PR,STDIO,5        ; Do the stdio thing, splat = CON:filename
  632.  
  633. *----- Error returns
  634.  
  635. PR_NOFILE    EQU    -1        ; Can't find or LoadSeg file.
  636. PR_NOMEM    EQU    -2        ; No memory for one thing or another
  637. PR_NOCLI    EQU    -3        ; Caller must be CLI (SyncRun() only).
  638.  
  639. PR_NOSLOT    EQU    -4    ; No slot in task array
  640. PR_NOINPUT    EQU    -5    ; Can't get input file
  641. PR_NOOUTPUT    EQU    -6    ; Can't get output file
  642. PR_NOLOCK    EQU    -7    ; Problem obtaining locks
  643. PR_ARGERR    EQU    -8    ; Bad Argument
  644. PR_NOBCPL    EQU    -9    ; Bad program passed to ASyncRun
  645. PR_BADLIB    EQU    -10    ; Bad library version
  646. PR_NOSTDIO    EQU    -11    ; Couldn't get stdio handles.
  647.  
  648. *---------- Programs should return this as result2 if no CLI:
  649.  
  650. ERROR_NOT_CLI    EQU    400    ; Program/function needed a CLI
  651.  
  652. *-------------------------------- Resident Program support -------*
  653. *--- This node is allocated for you when you AddResidentPrg() a segment.
  654. *--- They are stored as a single linked list with the root in ArpBase,
  655. *--- if you absolutely *must* wander through this list instead of
  656. *--- using the supplied functions, then you must first obtain the
  657. *--- the semaphore which protects this list, and then release it afterwards.
  658. *--- Do not use Forbid() and Permit() to gain exclusive access!
  659. *------------------------------------------------------------------*
  660.  
  661.     STRUCTURE ResidentProgramNode,0
  662.         CPTR    rpn_Next        ; next node, or NULL
  663.         LONG    rpn_Usage        ; Number of times this code is used
  664.         ULONG    rpn_CheckSum        ; checksum for this code
  665.         BPTR    rpn_Segment        ; the segment
  666.         LABEL    rpn_Name        ; the name of the program.
  667.         LABEL    rpn_SIZEOF
  668.  
  669. *--- If your program starts with this structure, ASyncRun() and SyncRun()
  670. *--- will override a users stack request with the value in rpt_StackSize.
  671. *--- Furthermore, if you are actually attached to the resident list,
  672. *--- a memory block of size rpt_DataSize will be allocated for you, and
  673. *--- a pointer to this data passed to you in register A4.  You may use this
  674. *--- block to clone the data segment of programs, thus resulting in
  675. *--- one copy of text, but multiple copies of data/bss for each process
  676. *--- invocation.  If you are resident, your program will start at rpt_Instruction,
  677. *--- otherwise, it will be launched from the initial branch.
  678.  
  679.  
  680.     STRUCTURE    ResidentProgramTag,0
  681.         BPTR    rpt_NextSeg    ; provided by DOS at LoadSeg time.
  682.         UWORD    rpt_BRA        ; Short branch to executable
  683.         UWORD    rpt_Magic    ; resident majik value
  684.         ULONG    rpt_StackSize    ; min stack for this process
  685.         ULONG    rpt_DataSize    ; Size of data allocation (may be zero)
  686.         LABEL    rpt_Instruction    ; start here if resident
  687.  
  688. ************* The form of the ARP allocated node in your tasks memlist when
  689. ************* launched as a resident program, note that the data portion
  690. ************* of the node will only exist if you have specified a nonzero
  691. ************* value for rpt_DataSize. Note also that this structure is READ ONLY,
  692. ************* modify values in this at your own risk. The stack stuff is for
  693. ************* tracking, if you need actual addresses or stacksize, check the
  694. ************* normal places for it in your process/task structure.
  695.  
  696.     STRUCTURE ProcessMemory,LN_SIZE
  697.         UWORD    pm_Num        ; number of entries, 1 if no data 2 if data
  698.         CPTR    pm_Stack
  699.         ULONG    pm_StackSize
  700.         CPTR    pm_Data        ; pointer to data
  701.         ULONG    pm_DataSize
  702.         LABEL    pm_Sizeof
  703. * Search for the name below on your TC_MEMENTRY list if you need to
  704. * get the above node.  Remember, you modify the above at your own
  705. * risk!
  706. *
  707. PMEM_NAME    MACRO
  708.     dc.b    'ARP_PMEM',0    ; memlist node for stack and/or data
  709.     ds.w    0
  710.     ENDM
  711.  
  712. RESIDENT_MAGIC        EQU    $4AFC        ; same as RTC_MATCHWORD (trapf)
  713.  
  714. ********** Note that the initial branch and the rpt_Instruction do not
  715. ********** have to be the same.  This allows different actions to be taken
  716. ********** if you are diskloaded or resident.  DataSize memory will be allocated
  717. ********** only if you are resident, but stacksize will override all user
  718. ********** stack requests.
  719. **********
  720. ********** Macro to facilitate initialization of this structure, place at start
  721. ********** of code.
  722. ********** Usage is RESIDENT STACKSIZE [ optional  DATASIZE LABEL ]
  723.  
  724. RESIDENT MACRO
  725.  IFEQ NARG
  726.     FAIL
  727.  ENDC
  728.  IFC '\3',''
  729.     bra.s    resident_start\@    ; branch to rp_instruction
  730.  ENDC
  731.  IFNC '\3',''
  732.     bra.s    \3        ; branch to user label
  733.  ENDC
  734.     dc.w    RESIDENT_MAGIC        ; our magic value
  735.     dc.l    \1            ; stacksize
  736.  IFNC '\2',''
  737.     dc.l    \2            ; datasize
  738.  ENDC
  739.  IFC '\2',''
  740.     dc.l    0            ; of zero
  741.  ENDC
  742. resident_start\@
  743.     ENDM
  744.  
  745. *--------- String/Date structures etc
  746.     STRUCTURE    DateTime,0
  747.     STRUCT    dat_Stamp,ds_SIZEOF    ;DOS DateStamp
  748.     UBYTE    dat_Format        ;controls appearance of dat_StrDate
  749.     UBYTE    dat_Flags        ;see BITDEF's below
  750.     CPTR    dat_StrDay        ;day of the week string
  751.     CPTR    dat_StrDate        ;date string
  752.     CPTR    dat_StrTime        ;time string
  753.     LABEL    dat_SIZEOF
  754. *
  755. * You need this much room for each of the DateTime strings:
  756. LEN_DATSTRING    EQU    10
  757.  
  758. *    flags for dat_Flags
  759. *
  760.     BITDEF    DT,SUBST,0        ;substitute Today, Tomorrow, etc.
  761.     BITDEF    DT,FUTURE,1        ;day of the week is in future
  762. *
  763. *    date format values
  764. *
  765. FORMAT_DOS    equ    0
  766. FORMAT_INT    equ    1
  767. FORMAT_USA    equ    2
  768. FORMAT_CDN    equ    3
  769. FORMAT_MAX    equ    FORMAT_CDN
  770.  
  771. *---------- handy macros
  772.  
  773. LINKEXE    MACRO
  774.     LINKLIB    _LVO\1,4
  775.     ENDM
  776.  
  777. * LINKDOS now uses ArpBase
  778. * CALLDOS was nuked, to reduce confusion
  779.  
  780. LINKDOS    MACRO
  781.     jsr    _LVO\1(a6)
  782.     ENDM
  783.  
  784.  
  785. CALLEXE    MACRO
  786.     move.l    4,a6
  787.     jsr    _LVO\1(a6)
  788.     ENDM
  789.  
  790. * SYSCALL re-revised for only one arg
  791. *    DosBase should always use ArpBase, or DosBase, in A6
  792.  
  793. SYSCALL    MACRO
  794.     jsr    _LVO\1(A6)
  795.     ENDM
  796.  
  797. * Use this macro if arp.library can't be found.
  798. *    Note the assumption that stack is offset by 8 from return addr.
  799. *    After the macro, register A6 is ARPBASE
  800. *
  801.     IFD    MANX
  802. ALIBLNG    EQU    28
  803.     ENDC
  804.  
  805. * Use this macro to open arp.library and avoid recoverable alerts.
  806. * Saves D0/A0 on stack.
  807. * After executing, A6 = ARPBASE and stack points at D0/A0
  808. *
  809. OPENARP    MACRO
  810.     IFC    '\1',''
  811.     RESIDENT    4000,0
  812.     ENDC
  813.     movem.l    d0/a0,-(sp)
  814.     move.l    4,A6
  815.     lea.l    ARPNAME,a1        ; Get ArpBase
  816.     moveq.l    #ArpVersion,d0
  817.     SYSCALL    OpenLibrary
  818.     tst.l    d0
  819.     bne.s    okgo
  820.  
  821.     lea    dname,A1
  822.     SYSCALL    OpenLibrary
  823.     tst.l    D0
  824.     beq.s    1$
  825.     move.l    D0,A6
  826.     SYSCALL    Output            ;standard output file handle
  827.     move.l    d0,d1
  828.     beq.s    1$            ; No output. Phoey.
  829.     move.l    #alibmsg,d2        ;tell user he needs to find library
  830.     IFND    MANX
  831.     move.l    #aliblng,d3
  832.     ENDC
  833.     IFD    MANX
  834.     moveq    #ALIBLNG,d3
  835.     ENDC
  836.     SYSCALL    Write
  837. 1$:    addq    #8,sp
  838.     rts
  839.  
  840. dname    dc.b    'dos.library',0
  841. alibmsg    dc.b    'you need '
  842. ARPNAME:    ArpName
  843.     dc.b    ' V33+',$a
  844. aliblng    equ    *-alibmsg
  845.     ds.w    0
  846. okgo:    move.l    D0,A6
  847.     ENDM
  848.  
  849.  
  850.     INCLUDE    "arpcompat.i"
  851.  
  852.     ENDC    !LIBRARIES_ARPBASE_I
  853.